```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nginx 高并发实现原理深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero-section {
            background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
        }
        .article-title {
            font-family: 'Noto Serif SC', serif;
        }
        .section-title {
            font-family: 'Noto Serif SC', serif;
            position: relative;
            padding-left: 1.5rem;
        }
        .section-title:before {
            content: '';
            position: absolute;
            left: 0;
            top: 0.6em;
            height: 1.2em;
            width: 4px;
            background: #2563eb;
            border-radius: 2px;
        }
        .feature-card {
            transition: all 0.3s ease;
            border-left: 3px solid transparent;
        }
        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
            border-left: 3px solid #2563eb;
        }
        .code-block {
            font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
            background-color: #f8fafc;
            border-left: 3px solid #2563eb;
        }
        .diagram-container {
            background-color: #f8fafc;
            border-radius: 0.5rem;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-section text-white py-20 px-4">
        <div class="max-w-4xl mx-auto text-center">
            <h1 class="article-title text-4xl md:text-5xl font-bold mb-6 leading-tight">Nginx 高并发实现原理深度解析</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">探索百万级并发请求背后的技术实现</p>
            <div class="flex justify-center space-x-4">
                <span class="px-4 py-2 bg-blue-600 rounded-full text-sm font-medium">高性能服务器</span>
                <span class="px-4 py-2 bg-blue-600 rounded-full text-sm font-medium">架构设计</span>
                <span class="px-4 py-2 bg-blue-600 rounded-full text-sm font-medium">负载均衡</span>
            </div>
        </div>
    </section>

    <!-- Content Container -->
    <div class="max-w-4xl mx-auto px-4 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="prose max-w-none">
                <p class="text-lg text-gray-700 mb-6">当我们访问一个热门网站时，成千上万甚至数百万的用户同时进行请求，这样的巨大流量是如何被高效处理并快速响应的？Nginx 是由 Igor Sysoev 开发的高性能 HTTP 和反向代理服务器，自 2004 年发布以来，凭借其卓越的性能和轻量级的架构，迅速成为全球最受欢迎的 web 服务器之一。你可能在日常生活中已经无数次与 Nginx 打交道，但未必了解其背后的工作原理。</p>
                
                <div class="my-8">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1721007882473-329c642a-7ee1-4076-a55a-e9535addcfe1.png" alt="Nginx高并发示意图" class="rounded-lg shadow-md w-full">
                </div>
                
                <p class="text-lg text-gray-700">高并发是指系统能够同时处理大量请求的能力。在传统的阻塞式服务器架构中，每个请求通常对应一个独立的线程或进程。这种方法在面对大量并发请求时，会迅速消耗系统资源，导致性能瓶颈。然而，Nginx 采用了完全不同的设计理念——基于事件驱动和异步非阻塞的处理方式，使其在高并发场景下表现出色。</p>
            </div>
        </section>

        <!-- Architecture Section -->
        <section class="mb-20">
            <h2 class="section-title text-2xl md:text-3xl font-bold mb-8">Nginx的架构设计</h2>
            <p class="text-gray-700 mb-8">Nginx 的架构设计是其高性能和高并发处理能力的核心所在。了解 Nginx 的架构有助于我们深入理解其高效运行的原因，并能更好地应用和优化它。</p>
            
            <div class="my-8">
                <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1721007916174-c173c03f-13ce-4122-bc3b-c0ad0fa3072e.png" alt="Nginx架构图" class="rounded-lg shadow-md w-full">
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="feature-card bg-white p-6 rounded-lg shadow-sm">
                    <div class="flex items-center mb-4">
                        <div class="bg-blue-100 p-3 rounded-full mr-4">
                            <i class="fas fa-bolt text-blue-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold">事件驱动模型</h3>
                    </div>
                    <p class="text-gray-700">Nginx 采用事件驱动模型（Event-Driven Model），这是其高并发处理能力的基础。</p>
                    <ul class="mt-4 space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>异步非阻塞 I/O：Nginx 通过使用异步非阻塞 I/O，在等待 I/O 操作完成期间，能够继续处理其他请求。</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>Reactor 模型：使用单个主线程和多个工作线程，主线程负责监听和接受新连接，工作线程处理请求。</span>
                        </li>
                    </ul>
                </div>
                
                <div class="feature-card bg-white p-6 rounded-lg shadow-sm">
                    <div class="flex items-center mb-4">
                        <div class="bg-purple-100 p-3 rounded-full mr-4">
                            <i class="fas fa-sitemap text-purple-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold">多进程架构</h3>
                    </div>
                    <p class="text-gray-700">Nginx 采用多进程架构，以充分利用多核处理器，并提供更好的稳定性和隔离性。</p>
                    <ul class="mt-4 space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>主进程（Master Process）：负责管理整个 Nginx 实例，包括读取配置文件、创建监听端口等。</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>工作进程（Worker Processes）：负责处理客户端请求，彼此独立运行。</span>
                        </li>
                    </ul>
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="feature-card bg-white p-6 rounded-lg shadow-sm">
                    <div class="flex items-center mb-4">
                        <div class="bg-green-100 p-3 rounded-full mr-4">
                            <i class="fas fa-balance-scale text-green-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold">负载均衡和反向代理</h3>
                    </div>
                    <p class="text-gray-700">Nginx 的负载均衡和反向代理功能也是其高并发处理能力的重要组成部分。</p>
                    <ul class="mt-4 space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>负载均衡算法：包括轮询、最少连接、IP 哈希等。</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>反向代理：可以代理客户端请求，提供缓存、SSL 卸载等功能。</span>
                        </li>
                    </ul>
                </div>
                
                <div class="feature-card bg-white p-6 rounded-lg shadow-sm">
                    <div class="flex items-center mb-4">
                        <div class="bg-yellow-100 p-3 rounded-full mr-4">
                            <i class="fas fa-memory text-yellow-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold">内存管理和缓存机制</h3>
                    </div>
                    <p class="text-gray-700">Nginx 高效的内存管理和缓存机制也是其高性能的关键。</p>
                    <ul class="mt-4 space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>内存池（Memory Pool）：提高了内存操作的效率，减少内存碎片。</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>缓存机制：可以缓存静态资源、代理请求的响应等。</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Process Model Section -->
        <section class="mb-20">
            <h2 class="section-title text-2xl md:text-3xl font-bold mb-8">多进程和多线程模型</h2>
            <p class="text-gray-700 mb-8">Nginx 作为一款高性能的 HTTP 和反向代理服务器，其多进程和多线程模型设计是其实现高并发和高吞吐量的关键所在。</p>
            
            <div class="my-8">
                <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1721007946186-290405b6-5928-4417-a0e3-f806d2aa1bc5.png" alt="Nginx进程模型" class="rounded-lg shadow-md w-full">
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-project-diagram text-blue-500 mr-3"></i>
                        <span>多进程模型</span>
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <p>Nginx 主要采用多进程模型，这也是其高并发处理能力的核心。</p>
                        <p><strong>核心进程结构：</strong></p>
                        <ul class="space-y-2 pl-5 list-disc">
                            <li><strong>主进程（Master Process）</strong>：负责整个 Nginx 实例的管理和控制</li>
                            <li><strong>工作进程（Worker Processes）</strong>：负责实际的请求处理，每个工作进程独立运行</li>
                        </ul>
                        <p><strong>优势：</strong></p>
                        <ul class="space-y-2 pl-5 list-disc">
                            <li>高稳定性和可靠性：工作进程崩溃不会影响其他进程</li>
                            <li>充分利用多核 CPU：每个工作进程可以在不同 CPU 核上运行</li>
                        </ul>
                    </div>
                </div>
                
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-th text-purple-500 mr-3"></i>
                        <span>多线程模型</span>
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <p>虽然 Nginx 主要采用多进程模型，但它也支持多线程模式来优化性能。</p>
                        <p><strong>线程池机制：</strong></p>
                        <ul class="space-y-2 pl-5 list-disc">
                            <li>用于处理一些阻塞的 I/O 操作，如磁盘 I/O</li>
                            <li>工作进程可以将阻塞任务分发到线程池中的工作线程</li>
                        </ul>
                        <p><strong>优势：</strong></p>
                        <ul class="space-y-2 pl-5 list-disc">
                            <li>提高 I/O 处理效率：避免工作进程被阻塞</li>
                            <li>灵活性和扩展性：适应不同的负载和场景需求</li>
                        </ul>
                    </div>
                </div>
            </div>
            
            <!-- Mermaid Diagram -->
            <div class="diagram-container p-6 my-8">
                <div class="mermaid">
                    flowchart TD
                        A[主进程 Master Process] -->|管理| B[工作进程 Worker 1]
                        A -->|管理| C[工作进程 Worker 2]
                        A -->|管理| D[工作进程 Worker 3]
                        A -->|管理| E[工作进程 Worker N]
                        
                        B -->|事件循环| F[连接1]
                        B -->|事件循环| G[连接2]
                        B -->|事件循环| H[连接3]
                        
                        C -->|事件循环| I[连接4]
                        C -->|事件循环| J[连接5]
                        
                        D -->|事件循环| K[连接6]
                        D -->|事件循环| L[连接7]
                        
                        E -->|事件循环| M[连接8]
                        E -->|事件循环| N[连接9]
                </div>
            </div>
        </section>

        <!-- Connection Handling Section -->
        <section class="mb-20">
            <h2 class="section-title text-2xl md:text-3xl font-bold mb-8">高效的连接处理</h2>
            <p class="text-gray-700 mb-8">Nginx 以其高效的连接处理能力而著称，这主要归功于其事件驱动架构和非阻塞 I/O 模型。</p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-bolt text-orange-500 mr-3"></i>
                        <span>事件驱动架构</span>
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <p>Nginx 采用事件驱动架构（Event-Driven Architecture），这一架构使得 Nginx 能够高效地管理大量并发连接。</p>
                        <p><strong>关键实现：</strong></p>
                        <ul class="space-y-2 pl-5 list-disc">
                            <li><strong>非阻塞 I/O</strong>：在等待 I/O 操作完成时，进程可以继续处理其他请求</li>
                            <li><strong>I/O 多路复用</strong>：使用 epoll（Linux）或 kqueue（BSD）监控多个文件描述符</li>
                            <li><strong>事件循环</strong>：工作进程持续等待和处理 I/O 事件</li>
                        </ul>
                    </div>
                </div>
                
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-memory text-blue-500 mr-3"></i>
                        <span>内存管理和连接复用</span>
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <p>Nginx 在内存管理和连接复用方面也做了大量优化，以提高连接处理的效率。</p>
                        <p><strong>关键技术：</strong></p>
                        <ul class="space-y-2 pl-5 list-disc">
                            <li><strong>内存池（Memory Pool）</strong>：高效管理内存分配和释放</li>
                            <li><strong>保持连接（Keep-Alive）</strong>：复用已有连接，减少建立/关闭开销</li>
                            <li><strong>连接池</strong>：存储和复用已建立的连接</li>
                        </ul>
                    </div>
                </div>
            </div>
            
            <div class="bg-white p-6 rounded-lg shadow-sm mb-8">
                <h3 class="text-xl font-semibold mb-4 flex items-center">
                    <i class="fas fa-balance-scale text-purple-500 mr-3"></i>
                    <span>负载均衡和反向代理</span>
                </h3>
                <div class="space-y-4 text-gray-700">
                    <p>Nginx 的负载均衡和反向代理功能进一步增强了其高并发处理能力。</p>
                    
                    <div class="grid md:grid-cols-2 gap-6 mt-4">
                        <div>
                            <h4 class="font-medium mb-2 text-gray-800">负载均衡算法：</h4>
                            <ul class="space-y-2 pl-5 list-disc">
                                <li>轮询（Round Robin）</li>
                                <li>最少连接（Least Connections）</li>
                                <li>IP 哈希（IP Hash）</li>
                            </ul>
                        </div>
                        <div>
                            <h4 class="font-medium mb-2 text-gray-800">反向代理功能：</h4>
                            <ul class="space-y-2 pl-5 list-disc">
                                <li>缓存机制</li>
                                <li>SSL 卸载</li>
                                <li>访问控制</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Static Resources Section -->
        <section class="mb-20">
            <h2 class="section-title text-2xl md:text-3xl font-bold mb-8">静态资源和缓存机制</h2>
            <p class="text-gray-700 mb-8">Nginx 作为一个高性能的 HTTP 服务器和反向代理服务器，其在处理静态资源和缓存机制方面的设计极为出色，这使得它在处理高并发请求和提升性能方面具有明显优势。</p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-file-alt text-green-500 mr-3"></i>
                        <span>处理静态资源</span>
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <p><strong>文件系统访问优化：</strong></p>
                        <ul class="space-y-2 pl-5 list-disc">
                            <li>内存映射（Memory Mapping）</li>
                            <li>异步 I/O 操作</li>
                        </ul>
                        <p><strong>高效的数据传输：</strong></p>
                        <ul class="space-y-2 pl-5 list-disc">
                            <li>零拷贝技术</li>
                            <li>多进程架构</li>
                        </ul>
                    </div>
                </div>
                
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-database text-blue-500 mr-3"></i>
                        <span>缓存机制</span>
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <p><strong>静态资源缓存：</strong></p>
                        <ul class="space-y-2 pl-5 list-disc">
                            <li>缓存控制头</li>
                            <li>ETag 和 Last-Modified</li>
                        </ul>
                        <p><strong>代理缓存：</strong></p>
                        <ul class="space-y-2 pl-5 list-disc">
                            <li>代理缓存配置</li>
                            <li>缓存策略</li>
                        </ul>
                    </div>
                </div>
            </div>
            
            <div class="bg-white p-6 rounded-lg shadow-sm">
                <h3 class="text-xl font-semibold mb-4">实践中的缓存配置示例</h3>
                <div class="code-block p-4 rounded overflow-x-auto">
                    <pre class="text-sm"><code>http {
    # 定义缓存路径和缓存键
    proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=1g inactive=60m use_temp_path=off;

    server {
        listen 80;
        server_name example.com;

        # 静态资源缓存配置
        location /static/ {
            expires 30d;
            add_header Cache-Control "public";
        }

        # 代理缓存配置
        location / {
            proxy_pass http://backend_server;
            proxy_cache my_cache;
            proxy_cache_valid 200 302 10m;
            proxy_cache_valid 404 1m;
            proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
            add_header X-Proxy-Cache $upstream_cache_status;
        }
    }
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Load Balancing Section -->
        <section class="mb-20">
            <h2 class="section-title text-2xl md:text-3xl font-bold mb-8">负载均衡策略</h2>
            <p class="text-gray-700 mb-8">Nginx 的负载均衡策略是其高性能和高可扩展性的重要组成部分。Nginx 通过多种负载均衡算法和灵活的配置选项，能够有效地将客户端请求分发到多个后端服务器，从而提高系统的整体处理能力和可靠性。</p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-random text-purple-500 mr-3"></i>
                        <span>负载均衡算法</span>
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <div>
                            <h4 class="font-medium text-gray-800">轮询（Round Robin）</h4>
                            <p class="text-sm mt-1">将请求依次分配给后端服务器，简单而高效。</p>
                            <div class="code-block p-2 rounded mt-2 text-xs">
                                <pre><code>upstream backend {
    server backend1.example.com;
    server backend2.example.com;
}</code></pre>
                            </div>
                        </div>
                        
                        <div>
                            <h4 class="font-medium text-gray-800">最少连接（Least Connections）</h4>
                            <p class="text-sm mt-1">将请求分配给当前处理连接最少的服务器。</p>
                            <div class="code-block p-2 rounded mt-2 text-xs">
                                <pre><code>upstream backend {
    least_conn;
    server backend1.example.com;
    server backend2.example.com;
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-heartbeat text-red-500 mr-3"></i>
                        <span>健康检查机制</span>
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <div>
                            <h4 class="font-medium text-gray-800">被动健康检查</h4>
                            <p class="text-sm mt-1">通过监控后端服务器的响应状态码来判断其健康状态。</p>
                            <div class="code-block p-2 rounded mt-2 text-xs">
                                <pre><code>upstream backend {
    server backend1.example.com;
    server backend2.example.com max_fails=3 fail_timeout=30s;
}</code></pre>
                            </div>
                        </div>
                        
                        <div>
                            <h4 class="font-medium text-gray-800">主动健康检查</h4>
                            <p class="text-sm mt-1">通过定期发送检测请求来判断后端服务器的健康状态。</p>
                            <div class="code-block p-2 rounded mt-2 text-xs">
                                <pre><code>upstream backend {
    server backend1.example.com;
    server backend2.example.com;
    check interval=5000 rise=2 fall=5 timeout=4000 type=http;
    check_http_send "GET / HTTP/1.0\r\n\r\n";
    check_http_expect_alive http_2xx http_3xx;
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="bg-white p-6 rounded-lg shadow-sm">
                <h3 class="text-xl font-semibold mb-4">高级负载均衡配置</h3>
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <h4 class="font-medium text-gray-800 mb-2">会话保持（Session Persistence）</h4>
                        <div class="code-block p-2 rounded text-xs">
                            <pre><code>upstream backend {
    sticky cookie srv_id expires=1h domain=.example.com path=/;
    server backend1.example.com;
    server backend2.example.com;
}</code></pre>
                        </div>
                    </div>
                    
                    <div>
                        <h4 class="font-medium text-gray-800 mb-2">缓存机制</h4>
                        <div class="code-block p-2 rounded text-xs">
                            <pre><code>proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=my_cache:10m max_size=10g;
upstream backend {
    server backend1.example.com;
    server backend2.example.com;
}
location / {
    proxy_pass http://backend;
    proxy_cache my_cache;
    proxy_cache_valid 200 1h;
    add_header X-Proxy-Cache $upstream_cache_status;
}</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Performance Optimization Section -->
        <section class="mb-20">
            <h2 class="section-title text-2xl md:text-3xl font-bold mb-8">性能优化配置</h2>
            <p class="text-gray-700 mb-8">Nginx 性能优化是一项系统性的工作，需要结合具体的使用场景和硬件资源，进行全面的配置和调整。</p>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-network-wired text-blue-500 mr-3"></i>
                        <span>网络设置优化</span>
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <div>
                            <h4 class="font-medium text-gray-800">调整文件描述符限制</h4>
                            <div class="code-block p-2 rounded mt-2 text-xs">
                                <pre><code>worker_rlimit_nofile 65536;</code></pre>
                            </div>
                        </div>
                        
                        <div>
                            <h4 class="font-medium text-gray-800">优化 TCP 参数</h4>
                            <div class="code-block p-2 rounded mt-2 text-xs">
                                <pre><code>net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 1024 65000</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-tachometer-alt text-orange-500 mr-3"></i>
                        <span>进程配置优化</span>
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <div>
                            <h4 class="font-medium text-gray-800">配置工作进程数</h4>
                            <div class="code-block p-2 rounded mt-2 text-xs">
                                <pre><code>worker_processes auto;</code></pre>
                            </div>
                        </div>
                        
                        <div>
                            <h4 class="font-medium text-gray-800">优化工作进程连接数</h4>
                            <div class="code-block p-2 rounded mt-2 text-xs">
                                <pre><code>events {
    worker_connections 4096;
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="bg-white p-6 rounded-lg shadow-sm mt-8">
                <h3 class="text-xl font-semibold mb-4 flex items-center">
                    <i class="fas fa-shield-alt text-green-500 mr-3"></i>
                    <span>安全优化</span>
                </h3>
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <h4 class="font-medium text-gray-800 mb-2">启用 HTTPS</h4>
                        <div class="code-block p-2 rounded text-xs">
                            <pre><code>server {
    listen 443 ssl;
    server_name example.com;
    
    ssl_certificate /etc/nginx/ssl/example.com.crt;
    ssl_certificate_key /etc/nginx/ssl/example.com.key;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers 'HIGH:!aNULL:!MD5';
    
    location / {
        proxy_pass http://backend;
    }
}</code></pre>
                        </div>
                    </div>
                    
                    <div>
                        <h4 class="font-medium text-gray-800 mb-2">其他优化</h4>
                        <div class="code-block p-2 rounded text-xs">
                            <pre><code># 使用 Gzip 压缩
gzip on;
gzip_comp_level 5;
gzip_min_length 256;
gzip_proxied any;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

# 启用 HTTP/2
server {
    listen 443 ssl http2;
    server_name example.com;
}</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis',
                nodeSpacing: 50,
                rankSpacing: 50
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```